package com.ljx.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ljx.R;
import com.ljx.pojo.CrmBanner;
import com.ljx.service.impl.CrmBannerServiceImpl;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 李加喜
 * @date 2020/9/28 0028 21:11
 * @Email 1129071273@qq.com
 */
//用户能够执行的方法
@RestController
@RequestMapping("/educms/banner/front")
@CrossOrigin
@MapperScan("com.ljx.mapper")
public class BannerFrontController {
    @Autowired
    private CrmBannerServiceImpl crmBannerFrontService;
    //查询所有的Banner
    @GetMapping("/getAllBanner")
    @Cacheable(key = "'selectIndexList'",value = "banner")
    public R listBanner(){
        QueryWrapper<CrmBanner> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 2"); //可以实现对字符串的拼接
        List<CrmBanner> list = crmBannerFrontService.list(wrapper);
        return R.ok().data("list",list);
    }
}
